(ns clj-8583.format-iso8583
  (:use [clj-8583.format]
        [clj-8583.binary]))

(def field-definitions
  (make-field-definitions
    [[2 :pan (variable-length-field 2)]
    [3  :processing-code (fixed-length-field 6)]
    [4  :transaction-amount (fixed-length-field 12)]
    [7  :transmission-date-time (fixed-length-field 10)]
    [11 :stan (fixed-length-field 6)]
    [12 :local-time-transaction (fixed-length-field 6)]
    [13 :local-date-transaction (fixed-length-field 4)]
    [14 :card-expiry-date (fixed-length-field 4)]
    [15 :settlement-date (fixed-length-field 4)]
    [18 :merchant-type (fixed-length-field 4)]
    [22 :service-entry-mode (fixed-length-field 3)]
    [23 :card-sequence-number (fixed-length-field 3)]
    [25 :service-condition-mode (fixed-length-field 2)]
    [26 :pos-capture-code (fixed-length-field 2)]
    [28 :transaction-fee-amount (fixed-length-field 9)]
    [30 :transaction-processing-fee (fixed-length-field 9)]
    [32 :acquiring-institution-id (variable-length-field 2)]
    [33 :forwarding-institution-id (variable-length-field 2)]
    [35 :track-2 (variable-length-field 2)]
    [37 :retrieval-reference-number (fixed-length-field 12)]
    [39 :response-code (fixed-length-field 2)]
    [40 :service-restriction-code (fixed-length-field 3)]
    [41 :terminal-id (fixed-length-field 8)]
    [42 :card-acceptor-id (fixed-length-field 15)]
    [43 :card-acceptor-name-location (fixed-length-field 40)]
    [48 :additional-data-private (variable-length-field 3)]
    [49 :currency-code (fixed-length-field 3)]
    [52 :pin-data (fixed-length-field 8) :codec {:decoder bytes-to-hex}]
    [53 :security-related-control-infomation (fixed-length-field 16)]
    [54 :additional-amounts (variable-length-field 3)]
    [56 :message-reason-code (variable-length-field 3)]
    [59 :detail-inquiring (variable-length-field 3)]
    [60 :additional-service-info (variable-length-field 3)]
    [70 :network-managment-infomation (fixed-length-field 3)]
    [90 :original-data (fixed-length-field 42)]
    [96 :message-cecurity-code (fixed-length-field 8) :codec {:decoder bytes-to-hex :encoder hex-to-bytes}]
    [100 :receiving-institution-id-code (variable-length-field 2)]
    [103 :account-info (variable-length-field 2)]
    [123 :pos-data-code (variable-length-field 3)]
    [127 :postilion-private-data (variable-length-field 6)]
    [128 :mac (fixed-length-field 8) :codec {:decoder bytes-to-hex}]
]))


(def message-definitions
  {:0800 #{7 11 33 53 70 96},
   :0810 #{7 11 33 39 53 70 96},
   :0820 #{7 11 33 70},
   :0830 #{7 11 33 39 70},

   :0100 #{3 7 11 12 13 15 18 22 25 32 33 37 41 42 48 49 60 103},
   :0110 #{3 7 11 12 13 15 18 25 32 33 37 39 41 42 48 49 54 60 103},

   :0200 #{2 3 4 7 11 12 13 15 18 22 25 32 33 37 41 42 48 49 59 60 103},
   :0210 #{2 3 4 7 11 12 13 15 18 25 32 33 37 39 41 42 48 49 59 60 103},

   })
